<?php  
class ControllerTicketSetAssigner extends Controller {  
	private $error = array();
   
  	public function index() {
  		$this->load->language('ticket/set_assigner');
  		$this->load->model('ticket/set_assigner');
  		
  		if (($this->request->server['REQUEST_METHOD'] == 'POST')) {
  			$this->model_ticket_set_assigner->addAssigner($this->request->post['id']);
  			
  			$this->session->data['success'] = $this->language->get('text_success');
  			
  			$this->redirect($this->url->link('ticket/set_assigner', 'token=' . $this->session->data['token'], 'SSL'));
  		}

    	$this->document->setTitle($this->language->get('heading_title'));
    	
    	$this->data['breadcrumbs'] = array();

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => false
   		);

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('ticket/set_assigner', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => ' :: '
   		);
	
		$assigners = $this->model_ticket_set_assigner->getAssigners();
		
		$this->load->model( 'user/user_group');
		$groups = $this->model_user_user_group->getUserGroups();
		
		$this->data['groups'] = array();
		foreach ( $groups as $group ){
			$checked = '';
			foreach ( $assigners as $assigner ){
				if ( $assigner['user_group_id'] === $group['user_group_id'] ){
					$checked = 'checked="checked"';
					break;
				}
			}
			
			$this->data['groups'][] = array(
				'id' => $group['user_group_id'],
				'name' => $group['name'],
				'checked' => $checked
			);
		}
		
		$this->data['text_save'] = $this->language->get('button_save');
		$this->data['text_assign'] = $this->language->get('text_assign');
		$this->data['text_group'] = $this->language->get('text_group');
		$this->data['heading_title'] = $this->language->get('heading_title');
		$this->data['action'] = $this->url->link('ticket/set_assigner', 'token=' . $this->session->data['token'], 'SSL');
		
  		if (isset($this->session->data['success'])) {
			$this->data['success'] = $this->session->data['success'];
		
			unset($this->session->data['success']);
		} else {
			$this->data['success'] = '';
		}
		
    	$this->template = 'ticket/set_assigner.tpl';
		$this->children = array(
			'common/header',
			'common/footer'
		);
				
		$this->response->setOutput($this->render());
  	}
}
?>